#include <assert.h>
#include <iostream>
#include "Item.h"
#include "Global.h"
#include "TextParser.h"

using std::cout; using std::endl;

void CItem::ShowName()
{
#ifdef _WIN32
	SetConsoleTextAttribute( hConsoleHandle, ITEM_NAME_COLOR|0 );
	cout << szName;
#else
    printf(ITEM_NAME_STRING, szName);
#endif
}

void CItem::ShowDetail()
{
	//物品描述
	ShowName();
	cout << endl;
#ifdef _WIN32_
	SetConsoleTextAttribute( hConsoleHandle, DESCRIPTION_COLOR|0 );
	cout << szDesc << endl;
#else
    printf(DESCRIPTION_STRING, szDesc);
    cout << endl;
#endif
}

void CFood::ShowDetail()
{
    // call the method of base class
    CItem::ShowDetail();
    cout << "可以服用！";
	if ( nAddHP )
		cout << "生命 + " << nAddHP << "。\t";
	if ( nAddMaxHP)
		cout <<"生命上限 + " << nAddMaxHP << "。\t";
	if ( nAddMP )
		cout <<"内力 + " << nAddMP <<"。\t";
	if ( nAddMaxMP)
		cout <<"内力上限 + " << nAddMaxMP <<"。\t";
    cout << endl;
}

bool CFood::Load(CTextParser &file)
{
    file.FindRecordHead();
    file.GotoNextLine();
    file.ReadString( szName );			//name
    file.GotoNextLine();
    file.ReadString( szDesc );			//description
		
    file.GotoNextLine();
    file.ReadInteger( &nAddHP);		//add hp
    file.ReadInteger( &nAddMaxHP);	//add max hp
    file.ReadInteger( &nAddMP);		//add mp
    file.ReadInteger( &nAddMaxMP);	//add max mp

    file.GotoNextLine();
    file.ReadInteger( &nCost );		//value
}

void CEquipment::ShowDetail()
{
    // call the method of base class
    CItem::ShowDetail();
    cout << "可以装备。";
	if ( nAddAttack)
		cout <<"攻击 + "<< nAddAttack <<"。\t";
	if ( nAddDefence)
		cout <<"护体 + " << nAddDefence <<"。\t";
	if ( nAddSpeed )
		cout <<"速度 + " << nAddSpeed <<"。\t";	
    cout << endl;
}

bool CEquipment::Load(CTextParser &file)
{
    file.FindRecordHead();
    file.GotoNextLine();
    file.ReadString( szName );			//name
    file.GotoNextLine();
    file.ReadString( szDesc );			//description
		
    file.GotoNextLine();
    file.ReadInteger( &nAddAttack);	//add attack
    file.ReadInteger( &nAddDefence);	//add defence
    file.ReadInteger( &nAddSpeed);	//add speed
		
    file.GotoNextLine();
    file.ReadInteger( &nLocation );	//location:head,foot...

    file.GotoNextLine();
    file.ReadInteger( &nCost );		//value
}

void CBook::ShowDetail()
{
    // call the method of base class
    CItem::ShowDetail();
    cout << "可以修习！";

	if ( nSkillIndex != -1 )
	{
		cout << "记载有武功：";
		// ShowSkillName( pGoods[nGoodsIndex].nSkillIndex );
		cout <<"。";
	}
		
	cout << endl;	
	//物品的效果
	// switch( pGoods[nGoodsIndex].nProperty ) {
	// case 2:
    //     break;
    // default:
    //     cout << "任务物品!";
	// }

}

bool CBook::Load(CTextParser &file)
{
    file.FindRecordHead();
    file.GotoNextLine();
    file.ReadString(szName);			//name
    file.GotoNextLine();
    file.ReadString(szDesc);			//description
		
    file.GotoNextLine();
    file.ReadInteger( &nSkillIndex);	//which skill to learn 

    file.GotoNextLine();
    file.ReadInteger( &nCost );		//value

    return true;
}
